<?php
namespace App\Module\User\Service;

use App\Constants\Constant;
use Hyperf\Di\Annotation\Inject;
use Qbhy\HyperfAuth\AuthManager;

class ScoreService {

    /**
     * @Inject()
     * @var AuthManager $authManager
     */
    private $authManager;

    public function search($pagesize){
        return $this->authManager->guard(Constant::USER)->user()->score->details()->latest("add_time")->paginate($pagesize);
    }

    public function getByCondition($direction,$origin,$date){
        $query = $this->authManager->guard(Constant::USER)->user()->score->details();

        if(!empty($direction)){
            $query->where("direction",$direction);
        }
        if(!empty($origin)){
            $query->where("origin",$origin);
        }
        if(!empty($date)){
            $query->whereDate("add_time",$date);
        }

        return $query->first();
    }
}